package edu.umassd.raddacl.steps;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import edu.umassd.raddacl.Cluster;
import edu.umassd.raddacl.RADDACL;

/**
 * This is the first step performed in {@link RADDACL}. It populates the
 * clusters collection with a set of clusters that represent the smallest amount
 * of data.
 * 
 * @author Dan Avila
 * 
 */
@Component
public class Preclustering
{
	@Autowired
	private PreclusterThreshold threshold;

	private Collection<Cluster> preClusters = new ArrayList<>();

	/**
	 * A recursive algorithm for identifying small clusters of related data
	 * inside this preclustering algorithm.
	 * 
	 * @param cluster
	 *            - the cluster to to precluster.
	 */
	public void perform(Cluster cluster)
	{
		if (threshold.isPrecluster(cluster))
		{
			preClusters.add(cluster);
		}
		else
		{
			for (Cluster child : cluster.split())
			{
				perform(child);
			}
		}
	}

	/**
	 * Gets the current set of preclusters.
	 * 
	 * @return the collection of preclusters generated by
	 *         {@link #perform(Cluster)}
	 */
	public Collection<Cluster> getPreClusters()
	{
		return preClusters;
	}
}
